package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 读取配置文件
 */
@Component
@RestController
@RequestMapping("/config")
@PropertySource(value = {"classpath:girl/girl.properties"})
public class ReadConfigController {
    @Value("${server.port}")
    private String port;
    @Value("${girl.name}")
    private String name;
    @Value("${girl.age}")
    private String age;
    @Autowired
    private Environment evn;
    @GetMapping("/getGirl")
    public String getGirl(){
        return name + age;
    }

    @GetMapping("/value")
    public String valueConfig(){
        return port;
    }
    @GetMapping("/env")
    public String envConfig(){
        return evn.getProperty("server.port");
    }
    @GetMapping("/badGirl")
    public String badGirl(){
        String[] girl = new String[1];
        return girl[1];
    }

    public static void main(String[] args) {
        ReadConfigController read = new ReadConfigController();
      //  System.out.println(read.readConfig());
    }
}
